import math
import Hex

class Road:
  def __init__(self, edge_id, player = None):
    self.player = player
    self.edge_id = edge_id
    
  def __repr__(self):
    return "%d" % self.edge_id

  def __str__(self):
    return "%d" % self.edge_id

def get_longest_path(roads):
  return get_longest_path_helper(roads, None, [])
  
def next_to(road1, road2):
  return road2 in Hex.edge_to_edge_map[road1]

def get_longest_path_helper(roads, prev, exc):
  if not roads or (exc and len(roads) == len(exc)):
    return 0
  longest = 0 
  for road in roads:
    if (not exc or road not in exc) and (not prev or next_to(road.edge_id,prev.edge_id)):
      exc.append(road)
      cur = 1 + get_longest_path_helper(roads, road, exc)
      exc.remove(road)
      longest = max(cur, longest) 
  return longest

if __name__ == "__main__":    
  roads = [
         Road(edge_id=10),Road(edge_id=18),Road(edge_id=23),Road(edge_id=54),Road(edge_id=43),
         Road(edge_id=0),Road(edge_id=1),Road(edge_id=6),Road(edge_id=2),Road(edge_id=3),Road(edge_id=4),Road(edge_id=5),Road(edge_id=9) 
         ]
  #print roads
  print get_longest_path_helper(roads, None, [])    